package com.tencent.qf.user.controller;

import com.alibaba.fastjson.JSON;
import com.tencent.qf.common.aspect.annotation.ApiLog;
import com.tencent.qf.common.gateway.mks.MKSGatewayService;
import com.tencent.qf.common.gateway.mks.dto.MksCouponStatusCountBatchReq;
import com.tencent.qf.common.gateway.mks.dto.MksCouponStatusCountDTO;
import com.tencent.qf.common.gateway.mks.dto.MksCouponStatusCountReq;
import com.tencent.qf.common.pojo.HttpResult;
import com.tencent.qf.user.dto.MidApiUserInfo;
import com.tencent.qf.user.dto.WxpubSubscribeInfo;
import com.tencent.qf.user.dto.request.*;
import com.tencent.qf.user.dto.response.MksCouponInfoResponse;
import com.tencent.qf.user.service.MidApiUserService;
import com.tencent.qf.user.dto.request.MksCouponInfoRequest;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class MKSController {

    @Autowired
    private MKSGatewayService mksGatewayService;

    @PostMapping("/api/user/couponInfo")
    @ApiLog("用户券信息查询")
    public HttpResult<List<MksCouponStatusCountDTO>> mksCouponStatusCount(@RequestBody MksCouponInfoRequest request) {
        MksCouponStatusCountReq req = new MksCouponStatusCountReq();
        req.setStatus(request.getStatus());
        req.setAvailable_end_time_end(request.getEndTimeLimit());
        req.setWechat_user_union_id(request.getUnionId());
        req.setCreate_time_end(request.getCreateTimeEnd());
        List<MksCouponStatusCountDTO> dtos = mksGatewayService.mksCouponStatusCount(req);
        HttpResult<List<MksCouponStatusCountDTO>> result = HttpResult.success(dtos);
        return result;
    }

    @PostMapping("/api/user/couponInfo/batch")
    @ApiLog("用户券信息查询-批量")
    public HttpResult<Map<String, List<MksCouponStatusCountDTO>>> mksCouponStatusCountBatch(@RequestBody MksCouponInfoBatchRequest request) {
        MksCouponStatusCountBatchReq req = new MksCouponStatusCountBatchReq();
        req.setStatus(request.getStatus());
        req.setAvailable_end_time_end(request.getEndTimeLimit());
        req.setWechat_user_union_ids(request.getUnionIds());
        req.setCreate_time_end(request.getCreateTimeEnd());
        Map<String, List<MksCouponStatusCountDTO>> dtos = mksGatewayService.mksCouponStatusCountBatch(req);
        HttpResult<Map<String, List<MksCouponStatusCountDTO>>> result = HttpResult.success(dtos);
        return result;
    }
}
